/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin			*/
/*	Project:	GlbCloud			*/
/*	Author:		gong_libin			*/
/*	Date:		2013_08_30			*/
/*	File:		MrAcbm.h			*/
/********************************************************/

#ifndef	_MRACBM_H
#define	_MRACBM_H

#include "MrUtl.h"
#include <ctype.h>
#include <time.h>

#define	MR_ACBM				256

typedef struct tagMrAcbmData
{
	int m_iLength;
	UCHAR m_uszData[MR_BUFFER];
}MRACBMDATA_S;

typedef struct tagMrAcbmMatch
{
	int m_iIndex;
	ULONG m_ulOffset;
}MRACBMMATCH_S;

typedef struct tagMrAcbmNode
{
	int m_iLabel;
	int m_iDepth;

	UCHAR m_ucVal;
	int m_iGSShift;
	int m_iBCShift;

	int m_iChild;
	UCHAR m_ucChild;
	struct tagMrAcbmNode* m_pstParent;
	struct tagMrAcbmNode* m_pstChild[MR_ACBM];
}MRACBMNODE_S;

typedef struct tagMrAcbmTree
{
	int m_iPtnCount;
	int m_iMaxDepth;
	int m_iMinPtnSize;
	int m_iBCShift[MR_ACBM];
	MRACBMNODE_S* m_pstRoot;
	MRACBMDATA_S* m_pstPtnList;
}MRACBMTREE_S;

class CMrAcbm
{
public:
	CMrAcbm();
	virtual ~CMrAcbm();

	void MrAcbmShift();
	void MrAcbmclean();
	void MrAcbmGSShift();
	void MrAcbmBCShift();
	void MrAcbmGSShiftInit();
	void MrAcbmTreeClean(MRACBMNODE_S* pstRoot);
	int MrAcbmTreeBuild(MRACBMDATA_S* pstData, int iNumber);
	int MrAcbmGSShiftInitCore(MRACBMNODE_S* pstRoot, int iShift);
	int MrAcbmSetGSShift1(UCHAR* puszChar, int iDepth, int iShift);
	MRACBMTREE_S* MrAcbmTreeInit(MRACBMDATA_S* pstData, int iNumber);
	int MrAcbmSetGSShift2(UCHAR* puszOne, int iOne, UCHAR* puszTwo, int iTwo);
	int MrAcbmSearch(UCHAR* puszText, int iText, MRACBMMATCH_S stMatch[], int iMax);
	void MrAcbmDisplayKey(MRACBMDATA_S* pstData, int iNumber);
	void MrAcbmDisplayMatch(MRACBMDATA_S* pstData, MRACBMMATCH_S stMatch[], int iMatch);

private:
	MRACBMTREE_S* m_pstTree;

};

#endif /* _MRACBM_H */
